using GraphProcessor;
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.Logic;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    [System.Serializable, NodeMenuItem(LevelEditorConst.Execution + "/" + LevelEditorConst.FollowHero, typeof(LevelServiceGraph))]
    public class LevelServiceExecutionNode_FollowHero : LevelServiceExecutionNode
    {
        protected override ServiceExecutionType mServiceType => ServiceExecutionType.FollowHero;

        public override string name => LevelEditorConst.FollowHero;
        [Output("目标", false)] public EditorLevelServiceTargetSetter tagOrMcid;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.FollowHero, "跟随情况(开始跟随不管其他参数)")]
        public int isFollow;
        [InspectorName("停止跟随时是否改变朝向"), Tooltip("否为不改变，开始跟随不考虑这些参数")] public bool isSetRotation;
        [InspectorName("改变朝向rotationY")] public int stopRotationY;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.FollowHero, "停止跟随后实体站位(可不填)")]
        public Vector3 pos;

        protected override LevelServiceCustomConfig CreateConfig()
        {
            var rConfig = new LevelServiceExecutionCustom_FollowHero()
            {
                // tagOrMcid = this.tagOrMcid,
                isFollow = this.isFollow == 1,
                isSetRotation = this.isSetRotation,
                stopRotationY = this.stopRotationY,
                pos = new Int3(this.pos * 100)
            };
            this.tagOrMcid = new EditorLevelServiceTargetSetter(x => rConfig.tagOrMcid = x);
            return rConfig;
        }

        protected override void OnSync(EditorLevelServiceExecutionConfig newConfig, LevelServiceExecutionNode tempNode)
        {
            if (tempNode is LevelServiceExecutionNode_FollowHero rNode)
            {
                this.isFollow = rNode.isFollow;
                this.isSetRotation = rNode.isSetRotation;
                this.stopRotationY = rNode.stopRotationY;
                this.pos = rNode.pos;
            }
            if (newConfig.customConfig is LevelServiceExecutionCustom_FollowHero rConfig)
            {
                this.SyncTarget(rConfig.tagOrMcid);
            }
        }
    }
}